<?php
class ReportModel extends Model{
	private $table1 = 'report';
	private $table2 = 'products';
	private $table3 = 'membership';
	private $table4 = 'order';
	
	/**
	 * 根据会员id获取留言记录
	 * @param $uid
	 */
	public function getReportById($where,$uid,$system=''){
		$list = M($this->table1)->where($where)->order('report_id asc')->select();
		//echo M($this->table1)->getLastSql();die;
		 foreach($list as $key=>$val){
		 	//获取最后一次与管理员的留言
		 	$map['uid'] = $uid;
		 	$map['to_uid']  = $uid;
		 	$map['_logic'] = 'or';
		 	$where1['_complex'] = $map;
		 	if($system){
		 		$where1['reply_report_id'] = $val['reply_report_id'];
		 	}else{
		 		$where1['reply_report_id'] = $val['report_id'];
		 	}
		 	
		 	$result = M($this->table1)->where($where1)->order('report_id desc')->field('uid,to_uid,report_type')->find();
		 	//echo  M($this->table1)->getLastSql();die;
		 	if($result){
		 		$list[$key]['endreport']=$result;		 		
		 	}else{
		 		$list[$key]['endreport']=0;
		 	}		 	
		 	
		 }
		 return $list;
		//echo M($this->table1)->getLastSql();die;
	}
	
	/**
	 * 获取同一个记录的全部留言信息
	 * @param $where
	 */
	public function getAllReport($where){
		 return M($this->table1)->where($where)->select();
		// echo M($this->table1)->getLastSql();die;
	}
}